package com.un.ebs.sys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.un.ebs.sys.domain.ConfigureGroup;
import com.un.ebs.sys.dto.ConfigureGroupAddDto;
import com.un.ebs.sys.dto.ConfigureGroupUpdateDto;
import com.un.ebs.sys.mapper.ConfigureGroupMapper;
import com.un.ebs.sys.service.ConfigureGroupService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author liubo
 * @since 2019-11-03
 */
@Service
public class ConfigureGroupServiceImpl extends ServiceImpl<ConfigureGroupMapper, ConfigureGroup> implements ConfigureGroupService {

    @Override
    public void add(ConfigureGroupAddDto req) {
        ConfigureGroup obj = new ConfigureGroup();
        obj.setName(req.getName());
        obj.setAppId(req.getAppId());
        obj.setIsDelete(false);
        obj.setSort(getBaseMapper().maxSort());
        obj.insert();
    }

    @Override
    public void update(ConfigureGroupUpdateDto req) {
        ConfigureGroup obj = getById(req.getId());
        obj.setName(req.getName());
        obj.setAppId(req.getAppId());
        obj.updateById();
    }

    @Override
    public ConfigureGroup queryById(String id) {
        return getBaseMapper().selectById(id);
    }

    public void changeSort(String id, int index) {
        ConfigureGroup obj = getById(id);
        obj.setSort(index);
        getBaseMapper().updateById(obj);
    }

    @Override
    public void delete(String id) {
        getBaseMapper().deleteById(id);
    }

}